<?php
namespace admin\action;

use api\utils\PayApiClient;
use herosphp\bean\Beans;
use herosphp\http\HttpRequest;
use herosphp\string\StringUtils;
use herosphp\utils\AjaxResult;

/**
 * 大塑支付会员注册
 * @package admin\action
 * @author yangjian<yangjian102621@gmail.com>
 */
class PaymentUserAction extends CommonAction {

    //数据添加页面
    public function add(HttpRequest $request) {
        $this->setView('member/payment_user_add');
        $this->assign("title", "大塑账户注册");
        $this->assign('breadcrumb', array('MPE管理','MPE列表','MPE开通',$this->getTemplateVar('title')));
        $this->assign('breadUrl', array('javascript:;',url('admin/mpe/index'),url('admin/mpe/add'),'javascript:;'));
    }

    //插入数据操作
    public function insert(HttpRequest $request) {
        //处理参数
        $user = $request->getParameter('data');
        $user['password'] = md5(md5($user['password']));
        $user['ischecked'] = '1';
        $company = $request->getParameter('company');
        $company['main_business'] = StringUtils::jsonEncode($request->getParameter('main_business'));
        //调用远程API
        $resVo = PayApiClient::send('api/user/registerCompany', array('user' => $user, 'company' => $company));
        if ( !$resVo->isSucess() ) {
            AjaxResult::ajaxResult(AjaxResult::OP_FAILURE, $resVo->getMessage());
        }
        //添加操作日志
        $request->addParameter('logmessage', "添加用户[{$user['username']}]");

        AjaxResult::ajaxSuccessResult();  //操作成功

    }

}
